package com.uenpay.im.ui.old.activity.dynamic;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import android.text.TextUtils;

/**
 * serializer dynamic replys
 * 
 * @author aiti
 * 
 */
public class ReplySerializer {

	public static Reply deserializeUser(JSONObject json) {

		Reply Reply = new Reply();
		Reply.custid = json.optString("custid");
		Reply.nickname = json.optString("nickname");
		Reply.content = json.optString("content");
		Reply.replyid = json.optString("replyid");
		Reply.pcustid = json.optInt("pcustid");
		Reply.pnickname = json.optString("pnickname");

		return Reply;
	}

	public static ArrayList<Reply> deserializeUsers(JSONArray json) {
		ArrayList<Reply> Replys = new ArrayList<Reply>();
		for (int i = 0; i < json.length(); i++) {
			JSONObject jsonObject = json.optJSONObject(i);
			if (jsonObject != null) {
				if (!TextUtils.isEmpty(deserializeUser(jsonObject).custid)
						&& !TextUtils
								.isEmpty(deserializeUser(jsonObject).replyid)) {
					Replys.add(deserializeUser(jsonObject));
				}
			}
		}
		return Replys;
	}
}
